--
-- Author: ping.wang
-- Date: 2019-05-09 18:14:36
--
-- NewguildEmperorBookView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

local PriceBidTipsPanel = require("app.worldMap.views.bidding.PriceBidTipsPanel")

ClassRef.VIEW_ROOT_RES = Res.NewGuildEmperorBook

function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)
    local guildModel = app:getInst("NewguildModel")
    local myGuildInfo = guildModel:getMyGuildInfo()
    if myGuildInfo then
        local ownTownNum = myGuildInfo:getOwnTownNum()
        local totalProsperity = myGuildInfo:getTotalProsperity()
        local maxProsperity = myGuildInfo:getMaxProsperity()
        local openServerDays = app.session:getMerageOpenDays() -- 开服第几天
        local forceLimitInfo = GD:getForceLimitInfoByDay(openServerDays)

        local tempStr = string.format(L("guildwarexplain_string2"),maxProsperity)

        self._ui.Panel_right:findChild("Panel_text_2/text"):getVirtualRenderer():setLineHeight(30)
        if forceLimitInfo and (checknumber(forceLimitInfo.limitnum) == 0 or checknumber(forceLimitInfo.limitnum) > maxProsperity) then
            self._ui.Panel_right:findChild("Panel_text_2/text"):setString(tempStr)
        else
            self._ui.Panel_right:findChild("Panel_text_2/text"):setString(string.format("%s%s",tempStr,L("guildwarexplain_string3")))
        end

        self._ui.Panel_right:findChild("Panel_text_1/text"):setString(string.format(L("guildwarexplain_string1"),ownTownNum,totalProsperity))
        self._ui.Panel_right:findChild("Panel_text_1/text"):getVirtualRenderer():setLineHeight(30)
    end

    self._ui.Panel_right:findChild("Button/name"):setString(L("guildwarlimit_string4"))

    self._ui.Panel_right:findChild("Button"):addClickEventListener(function()
        --准备显示一下tips
        self:showTips()
    end)

end

function ClassRef:showTips()
    if cc.isDead( self._guildTips ) then
        self._guildTips = PriceBidTipsPanel.create()

        self._ui.tips:addChild( self._guildTips )
        -- 点击空白区域关闭
        display.nodeRemoveForNotHit(self._guildTips, function()
            if self._guildTips then
                self._guildTips:removeFromParent(true)
                self._guildTips = nil
            end
        end)
    end

    self._guildTips:setVisible( true )
    self._guildTips:setPosition(cc.p(0,0))
end

return ClassRef
